package com.zbkj.service.service.project.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.zbkj.common.enums.CommonStatusEnum;
import com.zbkj.common.model.project.ProjectInformation;
import com.zbkj.common.vo.CountVo;
import com.zbkj.service.dao.project.ProjectInformationMapper;
import com.zbkj.service.service.project.ProjectInformationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 项目资料表(客户端上传) 服务实现类
 * </p>
 *
 * @author 
 * @since 2024-07-06
 */
@Service
public class ProjectInformationServiceImpl extends ServiceImpl<ProjectInformationMapper, ProjectInformation> implements ProjectInformationService {

    @Resource
    private ProjectInformationMapper projectInformationMapper;

    @Override
    public List<ProjectInformation> getValidProjectInformationList(Long projectId) {
        if(Objects.isNull(projectId) || projectId.longValue()<=0) {
            return Lists.newArrayList();
        }
        LambdaQueryWrapper<ProjectInformation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ProjectInformation::getDeleteFlag, 0)
                .eq(ProjectInformation::getProjectId, projectId)
                .eq(ProjectInformation::getStatus, CommonStatusEnum.VALID_STATUS.getStatus());
        return this.list(queryWrapper);
    }

    @Override
    public boolean updateStatusToHis(Long projectId) {
        if(Objects.isNull(projectId) || projectId.longValue()<=0) {
            return false;
        }
        LambdaUpdateWrapper<ProjectInformation> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(ProjectInformation::getStatus, CommonStatusEnum.HIS_STATUS.getStatus())
                .eq(ProjectInformation::getProjectId, projectId)
                .eq(ProjectInformation::getStatus, CommonStatusEnum.VALID_STATUS.getStatus())
                .eq(ProjectInformation::getDeleteFlag, 0);
        return this.update(updateWrapper);
    }

    @Override
    public List<CountVo> prjectStatisDay(Integer status, String startDate, String endDate) {
        return projectInformationMapper.prjectStatisDay(status, startDate, endDate);
    }

    @Override
    public List<CountVo> prjectStatisMonth(Integer status, String startDate, String endDate) {
        return projectInformationMapper.prjectStatisMonth(status, startDate, endDate);
    }
}
